package com.timber.util;

import java.util.Vector;

import javax.swing.DefaultComboBoxModel;

import pv.jfcx.JPVChoiceNew;

public class SLChoice extends JPVChoiceNew
{

  public SLChoice()
  {
    setEditable(false);

  }

  public SLChoice( Vector v )
  {
    this( v.toArray() );

  }

  public SLChoice( Object[] arr )
  {
    this();
    setActionMask(EDIT_UPDATED);
    int i;
    if( arr == null )
      return;
    for( i = 0; i < arr.length; i++ )
      addItem( arr[i].toString() );

    setSelectedIndex( 0 );
  }


  public void setItems( Vector v )
  {
    m_list.clear();
    addItems( v );
  }


  public void addItems( Vector v )
  {
    int i;
    if( v == null )
      return;
    for( i = 0; i < v.size(); i++ )
      addItem( v.elementAt(i).toString() );
  }


  public void addItems( Object[] arr )
  {
    int i;
    if( arr == null )
      return;
    for( i = 0; i < arr.length; i++ )
      addItem( arr[i].toString() );

  }

/*
  public boolean isFocusTraversable()
  {
    return true;
  }
*/

  //----------------------------------------------------------------------

  /**
   *	emulate JComboBox methods
   */

  public void setSelectedItem( Object obj )
  {

    String str = obj.toString();

    int i = m_list.indexOf( obj );

    if( i < 0 )
      return;

    setSelectedIndex( i );

  }

  public Object getSelectedItem()
  {
    int i = getSelectedIndex();

    return m_list.elementAt(i);

  }

  public void setModel( DefaultComboBoxModel mdl )
  {
    int i;
    m_list.clear();
    for( i = 0; i < mdl.getSize(); i++)
      addItem( mdl.getElementAt(i) );

    setSelectedIndex( 0 );
  }
}
